***************************************************************************
* How does earmarked foreign aid affect recipient-country ownership?

/*	Table of contents
	1. Earmarked aid versus bilateral aid 
	2. Earmarked aid versus multilateral aid
	
	Contact: bernhard.reinsberg@glasgow.ac.uk  (22/11/2024)
*/	
***************************************************************************

* Earmarked aid versus bilateral aid 
***************************************************************************

* Factor analysis
*****************

  use "GPEDC_bilaterals", clear
  
  global D1 major eumember modelfp lme
  global D2 lnoda oda_gni mlshare 
  global D3 lngdppc growth icrg_qog rwgov
  
  ** Table A1 **
  corr dr_align_a*
  
  ** Table 1/2 ** 
  factor dr_align_a*, fa(1)
  qui predict Alignment
  
  keep if bimupr==1 | diso=="EU"
  
  
* Figures 
*********

  ** Figure 1 is drawn from the Earmarked Funding Dataset **

  preserve
  
   keep dr_align* Alignment year recipient riso donor diso 
   collapse dr_align_a* Alignment, by(diso donor riso recipient)
   
   egen _n_donor=count(Align), by(diso)
   egen _n_rec=count(Align), by(riso)
  
   ** Figure 2 **
   graph bar Alignment if _n_donor>5, over(donor, sort(Alignment) descending label(angle(90))) ytitle(Alignment score) scheme(idos)
   
   ** Figure 3 **
   graph bar Alignment if _n_rec>5, over(recipient, sort(Alignment) descending label(angle(90))) ytitle(Alignment score) scheme(idos)
  
  restore
  

* Main analysis 
***************

* Variables for regressions  

  g dr_emc=emc/totdr
  lab var dr_emc "Earmarking share"
  g dr_emc1=emc1/totdr1
  lab var dr_emc1 "Earmarking share (t-1)"
  g dr_emc3=emc3/totdr3
  lab var dr_emc3 "Average earmarking share (t-2, t-1, t)"
  g drsoft1=emc_soft1/totdr1
  lab var drsoft1 "Soft earmarking share"
  g drhard1=emc_strict1/totdr1
  lab var drhard1 "Strict earmarking share"
  g drsoft3=emc_soft3/totdr3
  lab var drsoft3 "Average soft earmarking share"
  g drhard3=emc_strict3/totdr3
  lab var drhard3 "Average strict earmarking share"  
  
 
* Overall alignment 
  
  qui reghdfe Alignment dr_emc3, a(year) cl(rcode)
  est store a11
  qui reghdfe Alignment dr_emc3, a(rcode year) cl(rcode)
  est store a12
  qui reghdfe Alignment dr_emc3, a(rcode##year) cl(rcode)
  est store a13
  
** Table 1
estout a1*, drop(_*) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N N_clust r2, fmt(0 0 3))


  qui reghdfe Alignment drsoft3 drhard3, a(year) cl(rcode)
  est store a21
  qui reghdfe Alignment drsoft3 drhard3, a(rcode year) cl(rcode)
  est store a22
  qui reghdfe Alignment drsoft3 drhard3, a(rcode##year) cl(rcode)
  est store a23
  
** Table 2
estout a2*, drop(_*) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N N_clust r2, fmt(0 0 3))


* Robustness tests
****************** 

* Descriptives statistics    
 
  qui reg dr_align_a1 dr_emc3 
  qui estpost su Alignment dr_align_a* dr_emc1 drsoft1 drhard1 $D1 $D2 $D3  if e(sample)
  
** Table A2 
  esttab ., cells("count(fmt(0)) mean(fmt(3)) sd(fmt(3)) min(fmt(3)) max(fmt(3))")
  

* Control variables

  qui reghdfe Alignment dr_emc3 $D1, a(rcode##year) cl(rcode)
  est store r11
  qui reghdfe Alignment dr_emc3 $D2, a(rcode##year) cl(rcode)
  est store r12
  qui reghdfe Alignment dr_emc3 $D3, a(rcode##year) cl(rcode)
  est store r13
  
** Table A3
estout r1*, drop(_*) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N N_clust r2, fmt(0 0 3))


* Donor-fixed effects
  
  qui reghdfe Alignment dr_emc3, a(dcode year) cl(rcode)
  est store r21
  qui reghdfe Alignment dr_emc3, a(dcode rcode year) cl(rcode)
  est store r22
  qui reghdfe Alignment dr_emc3, a(dcode##year) cl(rcode)
  est store r23
  qui reghdfe Alignment dr_emc3, a(rcode dcode##year) cl(rcode)
  est store r24
  
** Table A4
estout r2*, drop(_*) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N N_clust r2, fmt(0 0 3))


* Disaggregated indices 

  qui reghdfe dr_align_a1 dr_emc3, a(rcode##year) cl(rcode)
  est store r31
  qui reghdfe dr_align_a2 dr_emc3, a(rcode##year) cl(rcode)
  est store r32
  qui reghdfe dr_align_a3 dr_emc3, a(rcode##year) cl(rcode)
  est store r33
  qui reghdfe dr_align_a4 dr_emc3, a(rcode##year) cl(rcode)
  est store r34
   
** Table A5
estout r3*, drop(_*) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N N_clust r2, fmt(0 0 3))
 

* Disaggregated indices with controls

  qui reghdfe dr_align_a1 dr_emc3 $D1, a(rcode##year) cl(rcode)
  est store r41
  qui reghdfe dr_align_a2 dr_emc3 $D1, a(rcode##year) cl(rcode)
  est store r42
  qui reghdfe dr_align_a3 dr_emc3 $D1, a(rcode##year) cl(rcode)
  est store r43
  qui reghdfe dr_align_a4 dr_emc3 $D1, a(rcode##year) cl(rcode)
  est store r44
   
** Table A6
estout r4*, drop(_*) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N N_clust r2, fmt(0 0 3))
 
 
* With disaggregated predictor too 

  qui reghdfe dr_align_a1 drsoft3 drhard3 $D1, a(year) cl(rcode)  
  est store r51
  qui reghdfe dr_align_a2 drsoft3 drhard3 $D1, a(rcode year) cl(rcode)  
  est store r52
  qui reghdfe dr_align_a3 drsoft3 drhard3 $D1, a(rcode##year) cl(rcode)  
  est store r53
  qui reghdfe dr_align_a4 drsoft3 drhard3 $D1, a(rcode##year) cl(rcode)  
  est store r54
  
** Table A7
estout r5*, drop(_*) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N N_clust r2, fmt(0 0 3))
 
 
* Once-lagged effects 

  qui reghdfe Alignment dr_emc1, a(year) cl(rcode)
  est store r61
  qui reghdfe Alignment dr_emc1, a(rcode year) cl(rcode)
  est store r62
  qui reghdfe Alignment dr_emc1, a(rcode##year) cl(rcode)
  est store r63
  
** Table A8
estout r6*, drop(_*) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N N_clust r2, fmt(0 0 3))
 
 
  preserve
  
   keep dr_align* Alignment year recipient riso donor diso 
   egen _n_donor=count(Align), by(diso)
   
   collapse dr_align_a* Alignment _n_donor, by(donor diso year)
   
   reshape wide Alignment dr_align*, i(diso donor) j(year)
  
   ** Figure A1 **
   graph bar Alignment2015 Alignment2017 if _n_donor>5, over(donor, sort(diso) label(angle(90))) ytitle(Alignment score) legend(lab(1 "2015") lab(2 "2017")) scheme(s1mono)
        
  restore
  
  ** Figure A2 **
  twoway (scatter Alignment dr_emc) (lfit Alignment dr_emc), xtitle(Earmarking share) ytitle(Alignment score) legend(off) scheme(s1mono)
  
  
  qui reghdfe Alignment dr_emc3, a(rcode##year) cl(rcode)
  predict yhat, xb
  
  preserve
  collapse (mean)Alignment yhat dr_emc3, by(diso year)
   
  ** Figure A3 ** 
  twoway (scatter Align dr_emc3, mlab(diso)) (line yhat dr) if year==2017, xtitle(Earmarking share) ytitle(Alignment index) scheme(s1mono) legend(off)

  restore
  

* Earmarked aid versus multilateral aid
********************************************************************************

* Data 
******
  
  use "GPEDC_multilaterals", clear
  
  g emc_tot3=emc3/totdr3
  g lnemc_tot3=ln(1+emc_tot3)
  g lndr3=ln(1+totdr3)
  
  g soft3=emcs3/totdr3
  g lnsoft3=ln(1+soft3)
  g hard3=emch3/totdr3
  g lnhard3=ln(1+hard3)
  
  
* Analysis
**********
  
  qui reghdfe Alignment lnemc_tot3 lndr3, a(parentID year) cl(rcode)
  est store b11
  qui reghdfe Alignment lnemc_tot3 lndr3, a(parentID##year) cl(rcode)
  est store b12
  qui reghdfe Alignment lnemc_tot3 lndr3, a(parentID year rcode) cl(rcode)
  est store b13
  
** Table 4  
estout b1*, drop(_*) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N N_clust r2, fmt(0 0 3))
  
  est restore b11
  tab donor if e(sample)
  tab recipient if e(sample)
  su lnemc_tot3 if e(sample)
  di 0.353+0.646
  margins, at(lnemc_tot3=(0.353 1))
  
  
  qui reghdfe Alignment lnsoft3 lnhard3 lndr3, a(parentID year) cl(rcode)
  est store b21
  qui reghdfe Alignment lnsoft3 lnhard3 lndr3, a(parentID##year) cl(rcode)
  est store b22
  qui reghdfe Alignment lnsoft3 lnhard3 lndr3, a(parentID year rcode) cl(rcode)
  est store b23
  
** Table 5  
estout b2*, drop(_*) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N N_clust r2, fmt(0 0 3))
  
     
* Descriptives 
 
  est restore b13
  qui estpost su Alignment lnemc_tot3 lndr3  if e(sample)
  
** Table A2 (add data for 'IDO sample')
  esttab ., cells("count(fmt(0)) mean(fmt(3)) sd(fmt(3)) min(fmt(3)) max(fmt(3))") noobs

  
* end of do file *
